//
//  commentCell.m
//  百思不得姐comment
//
//  Created by 韦宗华 on 16/8/31.
//  Copyright © 2016年 joinWei. All rights reserved.
//

#import "commentCell.h"
#import "UIImageView+WebCache.h"
@interface commentCell ()

@property (weak, nonatomic) IBOutlet UILabel *userName;

@property (weak, nonatomic) IBOutlet UIImageView *userImage;

@property (weak, nonatomic) IBOutlet UILabel *commentLab;

@property (weak, nonatomic) IBOutlet UIButton *putUp;


@end
@implementation commentCell

- (IBAction)didClickBtn:(UIButton*)sender {
    
    sender.selected = ! self.commentmodel.isDing;
    self.commentmodel.Ding = sender.selected;
//    userModel* Model = [userModel userModelWithDic:self.commentmodel.user];

    if (sender.selected ==YES) {
//       NSString* str = Model.total_cmt_like_count;
//        int mun = [str floatValue];
//        [sender setTitle:[NSString stringWithFormat:@"%d",mun+1] forState:UIControlStateSelected];
//        Model.total_cmt_like_count =[NSString stringWithFormat:@"%d",mun+1];
//        

        //放大图片
        
        //添加动画效果
        UILabel* lab = [[UILabel alloc]initWithFrame:CGRectMake(sender.bounds.size.width/2, sender.bounds.size.height-30, sender.bounds.size.width, sender.bounds.size.height)];
        lab.text = @"+1";
        lab.font = [UIFont systemFontOfSize:13];
        lab.textColor = [UIColor redColor];
        lab.alpha = 0;
        [sender addSubview:lab];
        [UIView animateWithDuration:1 animations:^{
            sender.imageView.transform =CGAffineTransformMakeScale(0.5, 0.5);
            lab.transform = CGAffineTransformMakeScale(1.2, 1.2);
            lab.transform = CGAffineTransformTranslate(lab.transform, 20, -20);
            lab.alpha = 1;
            
            
            
            
        } completion:^(BOOL finished) {
            [lab removeFromSuperview];
            sender.imageView.transform =CGAffineTransformMakeScale(1, 1);

            
        }];
        
        
        
        
        
    }
}


-(void)setCommentmodel:(commentModel *)commentmodel
{
    _commentmodel = commentmodel;
    self.commentLab.text = commentmodel.content;
   userModel* model = [userModel userModelWithDic:commentmodel.user];
    self.userName.text  =model.username;
    [self.userImage sd_setImageWithURL:[NSURL URLWithString:model.profile_image]];
    self.userImage.layer.cornerRadius = 20;
    self.userImage.layer.masksToBounds = YES;
    [self.putUp setTitle:model.total_cmt_like_count forState:UIControlStateNormal];
    [self.putUp setTitle:[NSString stringWithFormat:@"%d",model.total_cmt_like_count.intValue+1] forState:UIControlStateSelected];

    if ([model.total_cmt_like_count isEqualToString:@"0"]) {
        [self.putUp setTitle:@"+1" forState:UIControlStateNormal];

        
    }
    
    self.putUp.selected = commentmodel.isDing;
    
    
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
